<template>
	<view class="login-page">
		<view class="login-page-title">密码登录</view>
		<view class="input-bar">
			<input class="input" placeholder-class="input-plc" maxlength="16" :password="!eyesOpen" v-model="password" placeholder="请输入密码"></input>
			<image class="eyes-icon" v-show="!eyesOpen" src="../../static/closeEyeIcon.png" @tap.stop="toggleEyes"></image>
			<image class="eyes-icon" v-show="eyesOpen" src="../../static/openEyeIcon.png" @tap.stop="toggleEyes"></image>
		</view>
		<largeBtn :disabled="btnDisabled" @btnClk="toLogin">登录</largeBtn>
		<view class="other-options">
			<view class="option-item" @tap.stop="toVcode">使用验证码登录</view>
			<view class="option-item" @tap.stop="toResetPossword">忘记密码</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex"
	export default {
		data() {
			return {
				phoneNum:'',
				password: '',
				eyesOpen: false
			}
		},
		onLoad(options){
			this.phoneNum = options.phone
		},
		computed:{
			...mapState(['fromVirtualId','fromUserId']),
			btnDisabled() {
				if(this.password){
					return false
				}
				return true
			}
		},
		mounted(){
		
		},
		
		methods: {
			toLogin() {
				uni.showLoading({mask: true});
				this.$api.login({ phone: this.phoneNum ,password: this.password}).then((res) => {
					this.$setToken(res)
					this.$getGlobalDataWhenLogin()
					if(this.fromVirtualId){
                        uni.reLaunch({
					        url: `/pages/commentDetail/index?fromUserId=${this.fromUserId}&virtualId=${this.fromVirtualId}`
					    });
					}else{
	                    uni.reLaunch({
					        url: '/pages/index/index?type=1'
					    });
					}
				})
			},
			toggleEyes(){
				this.eyesOpen = !this.eyesOpen
			},
			toVcode(){
				uni.navigateTo({
					url: `/pages/login/validateCode?phone=${this.phoneNum}&pageType=1`
				})
			},
			toResetPossword(){
				uni.navigateTo({
					url: `/pages/login/passwordAndVcode?phone=${this.phoneNum}&pageType=2`
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.login-page {
		width: 670rpx;
		margin: 0 auto;
		padding-top: 54rpx;

		.login-page-title {
			font-size: 48rpx;
			font-weight: 400;
			color: #323746;
			line-height: 60rpx;
		}

		.login-page-tips {
			margin-top: 16rpx;
			font-size: 24rpx;
			font-weight: 400;
			color: #9196A0;
			line-height: 32rpx;

			.deep-color {
				color: #323746;
			}
		}

		.input-bar {
			margin-top: 60rpx;
			margin-bottom: 120rpx;
			height: 120rpx;
			border-bottom: 2rpx solid #DDDDDD;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.input {
				width: 80%;
				font-size: 36rpx;
				font-weight: 400;
				color: #333;
				line-height: 44rpx;
			}
			.input-plc{
				color: #9196A0;
			}
			
			.eyes-icon{
				width: 40rpx;
				height: 40rpx;
			}
		}
		.other-options{
			margin:40rpx auto;
			width: 660rpx;
			display: flex;
			justify-content: space-between;
			.option-item{
				font-size: 24rpx;
				font-weight: 400;
				color: #2D82FF;
				line-height: 32rpx;
			}
		}
	}
</style>
